using System;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Input.Touch;
namespace WindowsGame4
{
    class gamePausedScreen : MenuScreen
    {
        #region Fields
        MenuEntry[] upgrades;
        MenuEntry resources;
        MenuEntry health;
        int numMinerals = GameManager.player.minerals;
        int numSpecimen = GameManager.player.specimens;
        int numUpgrades = 5;
        int rayGunLevel, saucerLevel;
        int saucerCost = 10000;
        int weaponCost = 1000;
        int specimenCost = 10;
      //  String thruster;
        #endregion

        #region Initialization
        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public gamePausedScreen():
            base("Hangar")
        {
                    rayGunLevel = GameManager.player.weapon.level;
                    saucerLevel = GameManager.player.saucerLevel;
            //thruster = "Exhaust";


            // Create our menu entries.
            upgrades = new MenuEntry[numUpgrades];
            resources = new MenuEntry(string.Empty);
            health = new MenuEntry(string.Empty);
            MenuEntries.Add(resources);
            MenuEntries.Add(health);

            for (int i = 0; i < numUpgrades; i++)
            {
                upgrades[i] = new MenuEntry(string.Empty);
                // Add entries to the menu.
                MenuEntries.Add(upgrades[i]);
            }


            SetMenuEntryText();
            // Hook up menu event handlers.
            upgrades[0].Selected += upgradeRaySelected;
            //upgrades[1].Selected += upgradeWaveSelected;
           // upgrades[2].Selected += upgradeGravitySelected;
            upgrades[1].Selected += upgradeSaucerSelected;
            //upgrades[3].Selected += upgradeThrusterSelected;
            health.Selected += fillHealthSelected;
        }

        void SetMenuEntryText()
        {
            numMinerals = GameManager.player.minerals;
            numSpecimen = GameManager.player.specimens;
            resources.Text = "Minerals: " + numMinerals + "                   Specimen: " + numSpecimen;
            upgrades[0].Text = "Upgrade RayGun     Level: " + rayGunLevel;
            //upgrades[1].Text = "WaveGun     Level: " + waveGunLevel;
           // upgrades[2].Text = "GravityGun     Level: " + gravityGunLevel;
            upgrades[1].Text = "Upgrade Saucer     Level: " + saucerLevel;
           // upgrades[3].Text = "Thrusters     " + thruster;
            health.Text = "Repair Ship";
        }

        #endregion

        #region Handle Input

        void upgradeRaySelected(object sender, PlayerIndexEventArgs e)
        {
            if (rayGunLevel < 5)
            {
                if ((numMinerals >= (weaponCost * rayGunLevel) + 100 && numMinerals > 0) &&
                    (numSpecimen >= (specimenCost * rayGunLevel) + 5 && numSpecimen > 0))
                {
                    GameManager.player.purchase((weaponCost * rayGunLevel) + 100, (specimenCost * rayGunLevel) + 5);
                    rayGunLevel++;
                }
                else
                {
                    LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new MessageBoxScreen("The ray gun upgrade costs " + ((weaponCost * rayGunLevel) + 100) + " Minerals and\n" + ((specimenCost * rayGunLevel) + 5) + " Specimen", false));
                }
            }
            GameManager.player.setWeapon(rayGunLevel); //---------------------------------- Pass a raygun?
            SetMenuEntryText();
        }

        /*void upgradeWaveSelected(object sender, PlayerIndexEventArgs e)
        {
            if (waveGunLevel < 5)
            {
                if ((numMinerals >= (weaponCost * waveGunLevel) + 100 && numMinerals > 0) &&
                    (numSpecimen >= (weaponCost * waveGunLevel) + 100 && numSpecimen > 0))
                {
                    GameManager.player.purchase((weaponCost * waveGunLevel) + 100, (weaponCost * waveGunLevel) + 100);
                    waveGunLevel++;
                }
                else
                {
                    LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new MessageBoxScreen("The wave gun upgrade costs " + ((weaponCost * waveGunLevel) + 100) + " of each resource", false));
                }
            }
            GameManager.player.setWeapon(1, waveGunLevel);
            SetMenuEntryText();
        }*/

      /*  void upgradeGravitySelected(object sender, PlayerIndexEventArgs e)
        {
            if (gravityGunLevel < 5)
            {
                if ((numMinerals >= (weaponCost * gravityGunLevel) + 100 && numMinerals > 0) &&
                    (numSpecimen >= (weaponCost * gravityGunLevel) + 100 && numSpecimen > 0))
                {
                    GameManager.player.purchase((weaponCost * gravityGunLevel) + 100, (weaponCost * gravityGunLevel) + 100);
                    gravityGunLevel++;
                }
                else
                {//Message with cost------------------------------------------------------------------------------------
                }
            }
            GameManager.player.setWeapon(2, gravityGunLevel);
            SetMenuEntryText();

        }*/

        void upgradeSaucerSelected(object sender, PlayerIndexEventArgs e)
        {
            if (saucerLevel < 3)
            {
                if ((numMinerals >= (saucerCost * saucerLevel) + saucerCost && numMinerals > 0) &&
                    (numSpecimen >= (specimenCost * saucerLevel) + saucerCost && numSpecimen > 0))
                {
                    GameManager.player.purchase((saucerCost * saucerLevel) + 2000, (specimenCost * saucerLevel) + 10);
                    saucerLevel++;
                }
                else
                {
                    LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new MessageBoxScreen("The new saucer costs " + ((weaponCost * saucerLevel) + 2000) + " Minerals and\n" + ((specimenCost * saucerLevel) + 10) + " Specimen", false));
                }
            }
            GameManager.player.setSaucer(saucerLevel);
            SetMenuEntryText();
        }

       /* void upgradeThrusterSelected(object sender, PlayerIndexEventArgs e)
        {
            if (thrusterLevel == 0)
            {
                thruster = "Exhaust"; 
                thrusterLevel++;
            }
            else
            {
                thruster = "SlingShot";
                thrusterLevel--;
            }

            GameManager.player.setExhaust(thrusterLevel);
            SetMenuEntryText();
        }*/

        void fillHealthSelected(object sender, PlayerIndexEventArgs e)
        {
             if ((numMinerals >= 300) && numMinerals > 0)
                {
                    GameManager.player.purchase(300, 0);
                    GameManager.player.curHealth = GameManager.player.maxHealth;
                }
                else
                {
                    LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new MessageBoxScreen("It costs " + 300 + " Minerals to repair to your ship", false));
                }

            SetMenuEntryText();      
        }

        public override void HandleInput(InputState input)
        {
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new BackgroundScreen(), new GameplayScreen());
            }
            base.HandleInput(input);
        }

        }


        #endregion
}